package de.clapp.backend.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class CipherServerThread extends Thread
{
    private final int port;
    
    public CipherServerThread(int port)
    {
        this.port = port;
        this.start();
    }

    @Override
    public void run()
    {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(3, 12, 5, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>());
        
        ServerSocket sSocket = null;
        try
        {
            sSocket = new ServerSocket(this.port);
            while (true)
            {
                executor.execute(new CipherServerRunnable(sSocket.accept()));
                System.out.println("Eingehende, sichere Verbindung");
            }
        }
        catch (IOException e1)
        {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        finally
        {
            try
            {
                sSocket.close();
            }
            catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }

}
